// 武汉绿地"生活与工作"报名H5




var path = require('path')
var routerApi = require('../../utils/routeString.js')(__filename, __dirname);
var utils = require('../../utils/index.js')
var validate = utils.validate;
var ip = utils.ip;
var SqlHelper = utils.SqlHelper;
var jwt = require('../../utils/jwt.js')



var uploadData = async function (req, res) {

    var body = req.body || req.query;
    var sqlHelper = new SqlHelper('checkin_whth0323');

    
    var data = {
        share: body.share
    }

    var results = await sqlHelper.asyncUpdate({Id:1},data);

    if (results.affectedRows > 0) {
        return res.send({ code: 1 , msg: "记录成功" });
    } else {
        return res.send({ code: 0, msg: "系统错误" });
    }
    
}
var selectData = async function (req, res) {

    var body = req.body || req.query;
    var sqlHelper = new SqlHelper('checkin_whth0323');

    
    var data = {
        share: body.share,
        id: body.id
    }

    var results = await sqlHelper.asyncSelect({Id:1});
    return res.send({ code: 1 , msg: "查询成功", "share":results[0].Share});
    // if (results.affectedRows > 0) {
    //     return res.send({ code: 1 , msg: "查询成功" , "share":results.share });
    // } else {
    //     return res.send({ code: 0, msg: "系统错误" });
    // }
    
}
// 命令解析
var analysisFn = function (req, res, next) {
    
    var body = req.body || req.query;

    var cmd = body.cmd;

    switch (cmd) {  
        case "upload":
            uploadData(req, res);
            break;
        case "select":
            selectData(req, res);
            break;
        default:
            return res.send({ code: 0, msg: '无效请求, cmd参数出错' });
    }
}

server.post({ path: routerApi, name: routerApi }, analysisFn)